package com.david.mydemo.ctl_es.model;

import org.springframework.http.HttpStatus;

import java.util.HashMap;

/**
 * @author hxtt
 *
 */
public class HxttResponse extends HashMap<String, Object>{
	private static final long serialVersionUID = -8713837118340960775L;

	public HxttResponse success() {
		this.code(HttpStatus.OK);
		this.message("success");
		this.data(null);
		return this;
	}

	public HxttResponse success(Object data) {
		this.code(HttpStatus.OK);
		this.message("success");
		this.data(data);
		return this;
	}

	public HxttResponse success(Object data, String message) {
		this.code(HttpStatus.OK);
		this.message(message);
		this.data(data);
		return this;
	}

	public HxttResponse fail() {
		this.code(HttpStatus.INTERNAL_SERVER_ERROR);
		this.data(null);
		this.message("error");
		return this;
	}

	public HxttResponse fail(String message) {
		this.code(HttpStatus.INTERNAL_SERVER_ERROR);
		this.data(null);
		this.message(message);
		return this;
	}

	public HxttResponse fail(HttpStatus status, Object data, String message) {
		this.code(status);
		this.data(data);
		this.message(message);
		return this;
	}

	public HxttResponse fail(Object data, String message) {
		this.code(HttpStatus.INTERNAL_SERVER_ERROR);
		this.data(data);
		this.message(message);
		return this;
	}

	public HxttResponse code(HttpStatus status) {
		this.put("code", status.value());
		return this;
	}

	public HxttResponse message(String message) {
		this.put("message", message);
		return this;
	}

	public HxttResponse data(Object data) {
		this.put("data", data);
		return this;
	}

	@Override
	public HxttResponse put(String key, Object value) {
		super.put(key, value);
		return this;
	}

}
